#include <htc.h>

/* Program device configuration word
 * Oscillator = HS
 * Watchdog Timer = Off
 * Power Up Timer = Off
 * Master Clear Enable = External
 * Code Protect = Off
 * Data EE Read Protect = Off
 * Brown Out Detect = BOD and SBOREN disabled
 * Internal External Switch Over Mode = Disabled
 * Monitor Clock Fail-safe = Disabled
 */
__CONFIG(HS & WDTDIS & PWRTDIS & MCLREN & UNPROTECT & UNPROTECT & BORDIS & IESODIS & FCMDIS);

// Peripheral initialization function
void init(void){
	/***** Common Code ****
	 *  Usart TX interrupt disabled.
	 *  Usart RX interrupt disabled.
	 */
	PIE1	= 0b00000000;
	/*
	 *  Portbit7:4 interrupt-on-change enabled
	 *  Peripheral interrupts not enabled
	 *  Global interrupt disabled during initialization
	 */
	INTCON	= 0b10001000;
	/*
	 *  Weak pullup on PORT disabled
	 */
	OPTION	= 0b10000000;
	/*
	 *  Port directions: 1=input, 0=output
	 */
	TRISC	= 0b11000000;
	
	/***** 16F690 Code ****
	 *  Internal oscillator set to 4MHz
	 */
	OSCCON	= 0b01100000;
	
	/***** PortA Code ****
	 *  Port directions: 1=input, 0=output
	 */
	TRISA	= 0b00000100;
	
	/***** PortB Code ****
	 *  Port directions: 1=input, 0=output
	 */
	TRISB	= 0b01010000;
	
	/***** Usart Code ****
	 *  High speed baud rate generator disabled
	 *  Usart in Asynchronous mode
	 *  Usart transmission enabled
	 *  TX in eight bit format
	 */
	TXSTA	= 0b00100000;
	/*
	 *  Usart reception enabled
	 *  RX in eight bit format
	 *  Usart module enabled
	 */
	RCSTA	= 0b10010000;
	/*
	 *  Baud rate is 9600
	 */
	SPBRG	= 0b00011001;
	
	ei();	// Global interrupts enabled
	
}
